package com.example.lib.c1;

/**
 * 和谐停止
 */
public class Main6Interrupt {

    private static class Runnable1 implements Runnable {
        @Override
        public void run() {
            String name = Thread.currentThread().getName();
//            while (!Thread.currentThread().isInterrupted()) {
            while (!Thread.interrupted()) {
                System.out.println(name + "---- is running " + Thread.currentThread().isInterrupted());
            }
            System.out.println(name + "---- is end " + Thread.currentThread().isInterrupted());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new Runnable1());
        thread1.start();
        Thread.sleep(3000);
        thread1.interrupt();//发起中断信号
    }

}
